package com.twu.biblioteca;

/**
 * Created by jfulton on 16/01/2014.
 */
public class Movie implements LibraryItem {
    String title;
    String year;
    String director;
    Integer rating;

    public Movie(String newTitle, String newYear, String newDirector, Integer newRating) {
        title = newTitle;
        year = newYear;
        director = newDirector;
        rating = newRating;
    }

    public String getRating() {
        if (ratingValid(rating)) {
            return rating.toString();
        } else {
            return "unrated";
        }
    }

    @Override
    public boolean matchesTitle(String title) {
        if (this.title == null) {
            return false;
        }
        return this.title.equals(title);
    }

    private boolean ratingValid(Integer testRating) {
        return (testRating >= 1 && testRating <= 10);
    }

    @Override
    public String toString() {
        return title + " (" + year + "), " + director + ", " + getRating();
    }
}
